package com.abc.model;

import lombok.Data;
import org.springframework.ai.document.Document;

import java.util.Map;

/**
 * 向量文档模型
 * 
 * @author abc
 * @since 2024-01-01
 */
@Data
public class VectorDocument {

    /**
     * 文档ID
     */
    private String id;

    /**
     * 文档内容
     */
    private String content;

    /**
     * 文档元数据
     */
    private Map<String, Object> metadata;

    /**
     * 转换为Spring AI Document
     */
    public Document toDocument() {
        Document document = new Document(content);
        document.getMetadata().putAll(metadata);
        return document;
    }

    /**
     * 从Spring AI Document创建
     */
    public static VectorDocument fromDocument(Document document) {
        VectorDocument vectorDocument = new VectorDocument();
        vectorDocument.setId(document.getId());
        vectorDocument.setContent(document.getText());
        vectorDocument.setMetadata(document.getMetadata());
        return vectorDocument;
    }
}

